
var assistantDemo = angular.module('assistantDemo', []);

function AssistantCtrl($scope, $http){

	$http({method: 'GET' , url: 'data.json'}).
		success(function(data, status, headers, config) {
//			alert(data);
			$scope.assistant = data;
			$scope.changeCurrentIndex(0);
		}).
		error(function(data, status, headers, config) {
//			alert(data);
		});

	$scope.currentIndex = 0;
	$scope.isCurrentIndex = function(testIndex){
		return $scope.currentIndex == testIndex;
	};

	$scope.changeCurrentIndex = function(newIndex){
		if (newIndex >= 0 && newIndex < $scope.assistant.steps.length){
			if ($scope.assistant.steps[newIndex].autoComplete){
				$scope.assistant.steps[newIndex].completed = true;
			};
			$scope.currentIndex = newIndex;
//			document.location.href = $scope.assistant.steps[newIndex].url;
		};
	};

	$scope.goToNext = function(){
		$scope.changeCurrentIndex($scope.currentIndex + 1);
	};

	$scope.goToPrevious = function(){
		$scope.changeCurrentIndex($scope.currentIndex - 1);
	};

	$scope.isCompleted = function(index){
		return $scope.assistant.steps[index].completed;
	};

	$scope.getImageOfStep = function(index){
		if ($scope.assistant.steps[index].completed){
			if ($scope.assistant.steps[index].images){
				return $scope.assistant.steps[index].images.completed;				
			} else{
				return $scope.assistant.images.completed;
			}
		} else{
			if ($scope.assistant.steps[index].images){
				return $scope.assistant.steps[index].images.notCompleted;
			} else{
				return $scope.assistant.images.notCompleted;
			};
		}
	};

	$scope.getTextOfStep = function(index){
		if ($scope.assistant.steps[index].completed){
			if (typeof $scope.assistant.steps[index].texts === 'undefined'){
				return $scope.assistant.texts.completed;
			} else{
				return $scope.assistant.steps[index].texts.completed;
			};
		} else{
			if (typeof $scope.assistant.steps[index].texts === 'undefined'){
				return $scope.assistant.texts.notCompleted;
			} else{
				return $scope.assistant.steps[index].texts.notCompleted;
			};
		}
	}

}